/**
 * 
 */
package cz.cuni.mff.abacs.burglar.visual.multithreading;

import cz.cuni.mff.abacs.burglar.logics.ExecutingMap;
import cz.cuni.mff.abacs.burglar.logics.storage.XMLLoader;


/**
 * Immutable cass.
 * 
 * Measures the executing time of the loading.
 * 
 * @author abacs
 *
 */
public class LoadingThread extends Thread {
	
	
	/** Address to return the results */
	private LoadingListener _listener;
	/**  */
	private final String _mapFile;
	
	
	// -------------------------------------------------------------------------
	// constructors:
	
	
	/**
	 *  
	 * 
	 * @param mapFileName
	 * @param listener
	 */
	public LoadingThread(String mapFileName, LoadingListener listener) {
		super();
		this._mapFile = mapFileName;
		this._listener = listener;
	}
	
	
	// -------------------------------------------------------------------------
	
	
	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {
		long startTime = System.currentTimeMillis();
		
		ExecutingMap map = XMLLoader.load(this._mapFile);
		ExecutingMap secondaryMap = XMLLoader.load(this._mapFile);
		
		long endTime = System.currentTimeMillis();
		
		long duration = endTime - startTime;
		
		System.out.println("- Map loading time: " + duration + " ms.");
		
		this._listener.loadingFinished(map, secondaryMap);
	}
	
	
	// -------------------------------------------------------------------------

}
